package com.fashion.web.actions;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fashion.model.News;
import com.fashion.model.NewsColumn;
import com.fashion.model.brand.Brand;
import com.fashion.model.gallery.Album;
import com.fashion.service.ColumnService;
import com.fashion.service.NewsService;
import com.fashion.service.brand.BrandService;
import com.fashion.service.gallery.AlbumService;
import com.fashion.utils.NewsTemplate;
import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller
@Namespace("/")
public class MainPageAction extends ActionSupport {
	List<News> focusNews = new ArrayList<News>();
	List<News> luxuryNews = new ArrayList<News>();
	List<News> videoNews = new ArrayList<News>();
	List<News> fashionNews = new ArrayList<News>();
	List<News> fineryNews = new ArrayList<News>();
	List<News> hairdressingNews = new ArrayList<News>();
	List<News> choicenessNews = new ArrayList<News>();
	List<News> storyNews = new ArrayList<News>();
	List<News> classroomNews = new ArrayList<News>();
	List<News> lifeNews = new ArrayList<News>();
	List<News> houseFurnitureNews = new ArrayList<News>();
	List<News> foodWineNews = new ArrayList<News>();
	List<News> specialNews = new ArrayList<News>();
	List<News> luxurySpecialNews = new ArrayList<News>();
	List<News> fashionSpecialNews = new ArrayList<News>();
	List<News> lifeSpecialNews = new ArrayList<News>();
	List<Album> albums = new ArrayList<Album>();
	List<News> peopleNews = new ArrayList<News>();
	List<News> activityNews = new ArrayList<News>();
	List<Brand> brands = new ArrayList<Brand>();

    //服饰资讯
    List<News> fuShiZuiXunNews = new ArrayList<News>();
    //街拍
    List<News> jiePaiNews = new ArrayList<News>();
    // 秀场大片
    List<News> xiuChangDaPianNews = new ArrayList<News>();
    // 搭配
    List<News> daPeiNews = new ArrayList<News>();
    //美容
    List<News> meiRongNews = new ArrayList<News>();
    //化妆品
    List<News> huaZhuangNews = new ArrayList<News>();
    //美体
    List<News> meiTiNews = new ArrayList<News>();
    //彩妆
    List<News> caiZhuangNews = new ArrayList<News>();
    //娱乐
    List<News> yuLeNews = new ArrayList<News>();


    @Resource(name = "albumService")
	private AlbumService albumService;
	@Resource(name = "newsService")
	private NewsService newsService;
	@Resource(name = "columnService")
	private ColumnService columnService;
	@Resource(name = "brandService")
	private BrandService brandService;
    private static final Logger logger = Logger.getLogger(MainPageAction.class);

    @Action(value = "index", results = {@Result(name = SUCCESS, location = "index.jsp"), @Result(name = ERROR, location = "error.jsp")})
	public String index() {
        try {
            List<NewsTemplate> templates = new ArrayList<NewsTemplate>();
            //foucs news
            templates.add(new NewsTemplate(5, 6));
            focusNews = newsService.searchNewsByTemplateList(templates, 2);
            //luxrry
            NewsColumn luxuryColumn = columnService.findColumnByUrl("luxury", "luxury");
            List<NewsColumn> luxuryColumns = columnService.getAllChildren(luxuryColumn);
            luxuryColumns.add(luxuryColumn);
            templates.clear();
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 3));
            templates.add(new NewsTemplate(2, 6));
            luxuryNews = newsService.searchNewsByColumnListAndTemplateList(luxuryColumns, templates, 2);
            //video
            templates.clear();
            NewsColumn videoColumn = columnService.findColumnByUrl("video", "video");
            List<NewsColumn> videoColumns = columnService.getAllChildren(videoColumn);
            videoColumns.add(videoColumn);
            templates.clear();
            templates.add(new NewsTemplate(4, 1));
            videoNews = newsService.searchNewsByColumnListAndTemplateList(videoColumns, templates, 2);
            //服饰
            templates.clear();
            NewsColumn fineryColumn = columnService.findColumnByUrl("fashion", "fushi");
            List<NewsColumn> fineryColumns = columnService.getAllChildren(fineryColumn);
            fineryColumns.add(fineryColumn);
            templates.add(new NewsTemplate(3, 1));
            templates.add(new NewsTemplate(2, 5));
            fineryNews = newsService.searchNewsByColumnListAndTemplateList(fineryColumns, templates, 2);
            //美容
            templates.clear();
            NewsColumn hairdressingColumn = columnService.findColumnByUrl("fashion", "meirong");
            List<NewsColumn> hairdressingColumns = columnService.getAllChildren(hairdressingColumn);
            hairdressingColumns.add(hairdressingColumn);
            templates.add(new NewsTemplate(2, 5));
            hairdressingNews = newsService.searchNewsByColumnListAndTemplateList(hairdressingColumns, templates, 2);
            //时尚
            templates.clear();
            NewsColumn fashionColumn = columnService.findColumnByUrl("fashion", "fashion");
            List<NewsColumn> fashionColumns = columnService.getAllChildren(fashionColumn);
            fashionColumns.add(fashionColumn);
            templates.add(new NewsTemplate(4, 2));
            fashionNews = newsService.searchNewsByColumnListAndTemplateList(fashionColumns, templates, 2);
            templates.clear();
            fashionColumns.removeAll(fineryColumns);
            fashionColumns.removeAll(hairdressingColumns);
            templates.add(new NewsTemplate(3, 6));
            fashionNews.addAll(newsService.searchNewsByColumnListAndTemplateList(fashionColumns, templates, 2));
            //豪宅 家居
            templates.clear();
            NewsColumn houseColumn = columnService.findColumnByUrl("life", "haozhai");
            List<NewsColumn> houseColumns = columnService.getAllChildren(houseColumn);
            houseColumns.add(houseColumn);
            NewsColumn furnitureColumn = columnService.findColumnByUrl("life", "jiaju");
            List<NewsColumn> furnitureColumns = columnService.getAllChildren(furnitureColumn);
            furnitureColumns.add(furnitureColumn);
            List<NewsColumn> houseFurnitureColumns = new ArrayList<NewsColumn>();
            houseFurnitureColumns.addAll(houseColumns);
            houseFurnitureColumns.addAll(furnitureColumns);
            templates.add(new NewsTemplate(2, 1));
            templates.add(new NewsTemplate(1, 5));
            houseFurnitureNews = newsService.searchNewsByColumnListAndTemplateList(houseFurnitureColumns, templates, 2);
            //美食 美酒
            templates.clear();
            NewsColumn foodColumn = columnService.findColumnByUrl("life", "meishi");
            List<NewsColumn> foodColumns = columnService.getAllChildren(foodColumn);
            foodColumns.add(foodColumn);
            NewsColumn wineColumn = columnService.findColumnByUrl("life", "meijiu");
            List<NewsColumn> wineColumns = columnService.getAllChildren(wineColumn);
            wineColumns.add(wineColumn);
            List<NewsColumn> foodWineColumns = new ArrayList<NewsColumn>();
            foodWineColumns.addAll(foodColumns);
            foodWineColumns.addAll(wineColumns);
            templates.add(new NewsTemplate(2, 1));
            templates.add(new NewsTemplate(1, 5));
            foodWineNews = newsService.searchNewsByColumnListAndTemplateList(foodWineColumns, templates, 2);
            //品味生活
            templates.clear();
            NewsColumn lifeColumn = columnService.findColumnByUrl("life", "life");
            List<NewsColumn> lifeColumns = columnService.getAllChildren(lifeColumn);
            lifeColumns.add(lifeColumn);
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 4));
            lifeNews = newsService.searchNewsByColumnListAndTemplateList(lifeColumns, templates, 2);
            templates.clear();
            lifeColumns.removeAll(foodColumns);
            lifeColumns.removeAll(wineColumns);
            templates.add(new NewsTemplate(2, 2));
            templates.add(new NewsTemplate(1, 12));
            lifeNews.addAll(newsService.searchNewsByColumnListAndTemplateList(lifeColumns, templates, 2));
            //专题
            templates.clear();
            NewsColumn specialColumn = columnService.findColumnByUrl("special", "special");
            List<NewsColumn> specialColumns = columnService.getAllChildren(specialColumn);
            specialColumns.add(specialColumn);
            templates.add(new NewsTemplate(4, 1));
            templates.add(new NewsTemplate(3, 2));
            templates.add(new NewsTemplate(2, 3));
            specialNews = newsService.searchNewsByColumnListAndTemplateList(specialColumns, templates, 2);

            templates.clear();
            NewsColumn luxurySpecialColumn = columnService.findColumnByUrl("special", "luxury");
            List<NewsColumn> luxurySpecialColumns = columnService.getAllChildren(luxurySpecialColumn);
            luxurySpecialColumns.add(luxurySpecialColumn);
            templates.add(new NewsTemplate(4, 4));
            luxurySpecialNews = newsService.searchNewsByColumnListAndTemplateList(luxurySpecialColumns, templates, 2);

            templates.clear();
            NewsColumn fashionSpeciaColumn = columnService.findColumnByUrl("special", "fashion");
            List<NewsColumn> fashionSpecialColumns = columnService.getAllChildren(fashionSpeciaColumn);
            fashionSpecialColumns.add(fashionSpeciaColumn);
            templates.add(new NewsTemplate(4, 4));
            fashionSpecialNews = newsService.searchNewsByColumnListAndTemplateList(fashionSpecialColumns, templates, 2);

            templates.clear();
            NewsColumn lifeSpeciaColumn = columnService.findColumnByUrl("special", "life");
            List<NewsColumn> lifeSpecialColumns = columnService.getAllChildren(lifeSpeciaColumn);
            lifeSpecialColumns.add(lifeSpeciaColumn);
            templates.add(new NewsTemplate(4, 4));
            lifeSpecialNews = newsService.searchNewsByColumnListAndTemplateList(lifeSpecialColumns, templates, 2);

            //人物
            templates.clear();
            NewsColumn peopleColumn = columnService.findColumnByUrl("people", "people");
            List<NewsColumn> peopleColumns = columnService.getAllChildren(peopleColumn);
            peopleColumns.add(peopleColumn);
            templates.add(new NewsTemplate(4, 1));
            templates.add(new NewsTemplate(3, 2));
            templates.add(new NewsTemplate(2, 3));
            templates.add(new NewsTemplate(1, 3));
            peopleNews = newsService.searchNewsByColumnListAndTemplateList(peopleColumns, templates, 2);

            //活动
           /* templates.clear();
            NewsColumn activityColumn = columnService.findColumnByUrl("activity", "activity");
            List<NewsColumn> activityColumns = columnService.getAllChildren(activityColumn);
            activityColumns.add(activityColumn);
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 4));
            activityNews = newsService.searchNewsByColumnListAndTemplateList(activityColumns, templates, 2);*/

            //new items added on 2013/12/22
            templates.clear();
            NewsColumn fuShiZiXunColumn = columnService.findColumnByUrl( "fashion" , "fushizuixun");
            List<NewsColumn> fuShiZiXunColumns = columnService.getAllChildren(fuShiZiXunColumn);
            fuShiZiXunColumns.add(fuShiZiXunColumn);
            templates.add(new NewsTemplate(3, 1));
            templates.add(new NewsTemplate(2, 5));
            fuShiZuiXunNews = newsService.searchNewsByColumnListAndTemplateList(fuShiZiXunColumns, templates, 2);

            templates.clear();
            NewsColumn jiePaiColumn = columnService.findColumnByUrl("fashion", "jiepai");
            List<NewsColumn> jiePaiColumns = columnService.getAllChildren(jiePaiColumn);
            jiePaiColumns.add(jiePaiColumn);
            templates.add(new NewsTemplate(3, 2));
            templates.add(new NewsTemplate(2, 8));
            jiePaiNews = newsService.searchNewsByColumnListAndTemplateList(jiePaiColumns, templates, 2);

            templates.clear();
            NewsColumn specificColumns = columnService.findColumnByUrl("fashion", "xiuchangdapian");
            List<NewsColumn> allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(3, 1));
            xiuChangDaPianNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            templates.clear();
            specificColumns = columnService.findColumnByUrl("fashion", "xiuchangdapian");
            allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(3, 2));
            templates.add(new NewsTemplate(2, 2));
            daPeiNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            templates.clear();
            specificColumns = columnService.findColumnByUrl("fashion", "meirong");
            allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(4, 6));
            meiRongNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            templates.clear();
            specificColumns = columnService.findColumnByUrl("fashion", "huazhuangpin");
            allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(2, 6));
            huaZhuangNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            templates.clear();
            specificColumns = columnService.findColumnByUrl( "fashion", "meiti" );
            allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(2, 15));
            templates.add(new NewsTemplate(3, 1));
            meiTiNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            templates.clear();
            specificColumns = columnService.findColumnByUrl("fashion", "caizhuang");
            allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(3, 1));
            caiZhuangNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            templates.clear();
            specificColumns = columnService.findColumnByUrl("news", "yule");
            allColumns = columnService.getAllChildren(specificColumns);
            allColumns.add(specificColumns);
            templates.add(new NewsTemplate(3, 1));
            templates.add(new NewsTemplate(2, 3));
            templates.add(new NewsTemplate(1, 3));
            yuLeNews = newsService.searchNewsByColumnListAndTemplateList(allColumns, templates, 2);

            //Brand
//            brands = brandService.find(1, 32, null);
            albums = albumService.find(null, null, "priority", 0, 5);
        } catch (Exception e) {
            logger.error("exception in MainPage:",e);

            return ERROR;
        }

        return SUCCESS;
	}

	public List<News> getLuxurySpecialNews() {
		return luxurySpecialNews;
	}

	public List<News> getFashionSpecialNews() {
		return fashionSpecialNews;
	}

	public List<News> getLifeSpecialNews() {
		return lifeSpecialNews;
	}

	public List<News> getActivityNews() {
		return activityNews;
	}

	public List<News> getFocusNews() {
		return focusNews;
	}

	public List<News> getLuxuryNews() {
		return luxuryNews;
	}

	public List<News> getVideoNews() {
		return videoNews;
	}

	public List<News> getFashionNews() {
		return fashionNews;
	}

	public List<News> getFineryNews() {
		return fineryNews;
	}

	public List<News> getHairdressingNews() {
		return hairdressingNews;
	}

	public List<News> getChoicenessNews() {
		return choicenessNews;
	}

	public List<News> getStoryNews() {
		return storyNews;
	}

	public List<News> getClassroomNews() {
		return classroomNews;
	}

	public List<News> getLifeNews() {
		return lifeNews;
	}

	public List<News> getFoodWineNews() {
		return foodWineNews;
	}

	public List<Album> getAlbums() {
		return albums;
	}

	public List<Brand> getBrands() {
		return brands;
	}

	public List<News> getPeopleNews() {
		return peopleNews;
	}

	public AlbumService getAlbumService() {
		return albumService;
	}

	public NewsService getNewsService() {
		return newsService;
	}

	public List<News> getHouseFurnitureNews() {
		return houseFurnitureNews;
	}

	public List<News> getSpecialNews() {
		return specialNews;
	}

    public List<News> getFuShiZuiXunNews() {
        return fuShiZuiXunNews;
    }

    public List<News> getJiePaiNews() {
        return jiePaiNews;
    }

    public List<News> getXiuChangDaPianNews() {
        return xiuChangDaPianNews;
    }

    public List<News> getDaPeiNews() {
        return daPeiNews;
    }

    public List<News> getMeiRongNews() {
        return meiRongNews;
    }

    public List<News> getHuaZhuangNews() {
        return huaZhuangNews;
    }

    public List<News> getMeiTiNews() {
        return meiTiNews;
    }

    public List<News> getCaiZhuangNews() {
        return caiZhuangNews;
    }

    public List<News> getYuLeNews() {
        return yuLeNews;
    }
}
